package cn.iocoder.yudao.module.project.controller.admin.weighthistoryorderedit;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.project.controller.admin.weighthistoryorderedit.vo.*;
import cn.iocoder.yudao.module.project.dal.dataobject.weighthistoryorderedit.WeightHistoryOrderEditDO;
import cn.iocoder.yudao.module.project.service.weighthistoryorderedit.WeightHistoryOrderEditService;

@Tag(name = "管理后台 - 订单编辑-删除相关称重业务")
@RestController
@RequestMapping("/project/weight-history-order-edit")
@Validated
public class WeightHistoryOrderEditController {

    @Resource
    private WeightHistoryOrderEditService weightHistoryOrderEditService;

    @PostMapping("/create")
    @Operation(summary = "创建订单编辑-删除相关称重业务")
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:create')")
    public CommonResult<Long> createWeightHistoryOrderEdit(@Valid @RequestBody WeightHistoryOrderEditSaveReqVO createReqVO) {
        return success(weightHistoryOrderEditService.createWeightHistoryOrderEdit(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新订单编辑-删除相关称重业务")
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:update')")
    public CommonResult<Boolean> updateWeightHistoryOrderEdit(@Valid @RequestBody WeightHistoryOrderEditSaveReqVO updateReqVO) {
        weightHistoryOrderEditService.updateWeightHistoryOrderEdit(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除订单编辑-删除相关称重业务")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:delete')")
    public CommonResult<Boolean> deleteWeightHistoryOrderEdit(@RequestParam("id") Long id) {
        weightHistoryOrderEditService.deleteWeightHistoryOrderEdit(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得订单编辑-删除相关称重业务")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:query')")
    public CommonResult<WeightHistoryOrderEditRespVO> getWeightHistoryOrderEdit(@RequestParam("id") Long id) {
        WeightHistoryOrderEditDO weightHistoryOrderEdit = weightHistoryOrderEditService.getWeightHistoryOrderEdit(id);
        return success(BeanUtils.toBean(weightHistoryOrderEdit, WeightHistoryOrderEditRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得订单编辑-删除相关称重业务分页")
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:query')")
    public CommonResult<PageResult<WeightHistoryOrderEditRespVO>> getWeightHistoryOrderEditPage(@Valid WeightHistoryOrderEditPageReqVO pageReqVO) {
        PageResult<WeightHistoryOrderEditDO> pageResult = weightHistoryOrderEditService.getWeightHistoryOrderEditPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WeightHistoryOrderEditRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出订单编辑-删除相关称重业务 Excel")
    @PreAuthorize("@ss.hasPermission('project:weight-history-order-edit:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWeightHistoryOrderEditExcel(@Valid WeightHistoryOrderEditPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WeightHistoryOrderEditDO> list = weightHistoryOrderEditService.getWeightHistoryOrderEditPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "订单编辑-删除相关称重业务.xls", "数据", WeightHistoryOrderEditRespVO.class,
                        BeanUtils.toBean(list, WeightHistoryOrderEditRespVO.class));
    }

}